package com.firstgroup.dms.controller;

import com.firstgroup.dms.common.Result;
import com.firstgroup.dms.pojo.DrugInformation;
import com.firstgroup.dms.service.impl.DrugInformationServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/drug")
public class DrugController {

    @Resource
    private DrugInformationServiceImpl drugInformationService;

    @GetMapping("/list")
    public Result getDrugList() {
        return drugInformationService.getAllDrugs();
    }

    @GetMapping("/{id}")
    public Result getDrugById(@PathVariable Integer id) {
        return drugInformationService.getDrugById(id);
    }

    @GetMapping("/categories")
    public Result getCategories() {
        return drugInformationService.getAllCategories();
    }

    @PostMapping("/add")
    public Result addDrug(@RequestBody DrugInformation drug) {
        return drugInformationService.insertDrug(drug);
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteDrug(@PathVariable Integer id) {
        return drugInformationService.deleteDrug(id);
    }
}